package com.ase.singleton.single;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author gyhstart
 * @create 2021/3/6 - 10:26
 **/
public class Singleton {
    private volatile static Singleton singleton = null;

    private Singleton() {

    }

    public static Singleton getInstance() {
        if (singleton == null) {
//            ReentrantLock lock = new ReentrantLock();
//            try {
//                lock.lock();
//                singleton = new Singleton();
//            }catch (Exception e){
//               e.printStackTrace();
//            }finally {
//                lock.unlock();
//            }


            synchronized (Singleton.class) {
                if (singleton == null) {
                    singleton = new Singleton();
                }
            }
        }
        return singleton;
    }
}
